import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Load your Excel file
file_path = r'C:\Users\SBD Lab\Desktop\BE_2024_daily.xlsx'
df = pd.read_excel(file_path)
df.columns = ['Datetime', 'Country', 'Carbon_intensity']
df['Datetime'] = pd.to_datetime(df['Datetime'])

# Add DayOfYear and Month
df['DayOfYear'] = df['Datetime'].dt.dayofyear
df['Month'] = df['Datetime'].dt.strftime('%b')

# Create the figure and heatmap
fig, ax = plt.subplots(figsize=(14, 2.8))  # Adjust height for clean layout
heatmap = sns.heatmap(
    [df['Carbon_intensity'].values],
    cmap='RdYlGn_r',
    cbar=True,
    cbar_kws={
        'orientation': 'horizontal',
        'label': 'Carbon Intensity [gCO₂/kWh]',
        'pad': 0.15  # Slightly closer to heatmap
    },
    vmin=0,
    vmax=300,
    ax=ax
)

# Set X-axis labels (months)
month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
               'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
tick_positions = [15, 45, 74, 105, 135, 165, 195, 225, 255, 285, 315, 345]
ax.set_xticks(tick_positions)
ax.set_xticklabels(month_names, rotation=0, fontsize=14)

# Remove y-axis labels
ax.set_yticks([])

# Set x-axis label just a little closer
ax.set_xlabel("Day (2024)", fontsize=13, labelpad=8)

# Set bold title
plt.title('Daily Carbon Intensity (Belgium 2024)', fontsize=18, fontweight='bold')

plt.tight_layout()
plt.show()
